"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RoomStatisticsDao = void 0;
const DbConfig_1 = require("../../src/config/DbConfig");
const DaoBase_1 = require("../../src/engine/dao/DaoBase");
const DateUtil_1 = require("../../src/engine/utils/DateUtil");
const Logger_1 = require("../../src/engine/utils/Logger");
const MysqlManager_1 = require("../../src/engine/utils/MysqlManager");
class RoomStatisticsDao extends DaoBase_1.DaoBase {
    static insert(param) {
        return __awaiter(this, void 0, void 0, function* () {
            let room_id = param["room_id"];
            let clubid = param["clubid"];
            let time = param["time"];
            let timeStr = DateUtil_1.default.formatDateStr(time);
            let client = yield MysqlManager_1.MysqlManager.instance.getDb(this.DB_NAME);
            let sql = "insert into t_room_statistics(room_id,clubid,time) values(?,?,?)";
            let sqlParams = [room_id, clubid, timeStr];
            let rows = yield client.queryPromise(sql, sqlParams);
        });
    }
    static get_statistics(club_id, startTime, endTime) {
        return __awaiter(this, void 0, void 0, function* () {
            let client = yield MysqlManager_1.MysqlManager.instance.getDb(this.DB_NAME);
            let sql = `select  * from  t_room_statistics where time >= ? and time < ? `;
            let sqlParams = [startTime, endTime];
            if (club_id > 0) {
                sql += " and clubid=?";
                sqlParams.push(club_id);
            }
            let results = yield client.queryPromise(sql, sqlParams);
            Logger_1.Logger.log("get_statistics==", sql, sqlParams, results);
            return results;
        });
    }
    static clear(delete_time) {
        return __awaiter(this, void 0, void 0, function* () {
            let client = yield MysqlManager_1.MysqlManager.instance.getDb(this.DB_NAME);
            let sql = "delete from t_room_statistics where time < ?";
            let sqlParams = [DateUtil_1.default.formatDateStr(delete_time)];
            yield client.queryPromise(sql, sqlParams);
        });
    }
}
exports.RoomStatisticsDao = RoomStatisticsDao;
RoomStatisticsDao.DB_NAME = DbConfig_1.DbConfig.Db_Name.db_admin;
